package com.zhoutao.blog.seven.utils;

import java.time.Duration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class TimeUtils {

    public final static DateTimeFormatter DEFAULT = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");

    private TimeUtils() {
    }

    public static String format(LocalDateTime time) {
        return time.format(DEFAULT);
    }

    /**
     * 计算两个时间的时间差
     *
     * @param time1
     * @param time2
     * @return
     */
    public static Long diff(LocalDateTime time1, LocalDateTime time2) {
        if (time1 == null || time2 == null) {
            return Long.MAX_VALUE;
        }
        return Math.abs(Duration.between(time1, time2).toMillis());
    }
}
